home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #39 (Dec 88) / SmoothSource / Smooth.asm next >
Assembly Source File  |  1988-06-23  |  31KB  |  1,234 lines

  1. ; ----------------------------------------------------------
  2. ; - Smoother: picCommenting polygons & non solo ------------
  3. ; - Raul Tabasso - via delle Isole 23/A - 00198 ROMA -------
  4. ; ------------------------------------------------------------------------
  5. ; WARNING: because this program is intended as a demo, there are some
  6. ;       circumstances where a stronger error checking should be applied.
  7. ;       Due to this, situations where a potential problem may arice,
  8. ;      are marked with a (¿) symbol and a short advice is given.
  9. ; ------------------------------------------------------------------------
  10. Include    picCommenting:SmoothSource:Traps.D
  11. ; ----------------------------------------------        
  12. MBarHeight    EQU    $BAA        ;GENERAL EQUATES
  13. DoubleTime    EQU    $2F0
  14. screenBits    EQU    $FF86
  15. PortRect        EQU    16
  16. ; ----------------------------------
  17. PrGlue        EQU    $A8FD        ;New print manager call
  18. PrOpen        EQU    $C8000000    ;PrGlue's routine selectors
  19. PrClose        EQU    $D0000000
  20. PrintDefault    EQU    $20040480
  21. PrStlDialog    EQU    $2A040484
  22. PrJobDialog    EQU    $32040488
  23. PrOpenDoc    EQU    $04000C00
  24. PrCloseDoc    EQU    $08000484
  25. PrOpenPage    EQU    $10000808
  26. PrClosePage    EQU    $1800040C
  27. PrPicFile    EQU    $60051480
  28. PrError        EQU    $BA000000
  29. ; ----------------------------------
  30. iCopies        EQU    4        ;Print Manager Stuff
  31. prInfo        EQU    2
  32. prJob        EQU    62
  33. rPage        EQU    6
  34. bJDocLoop    EQU    6
  35. ; -----------------------------------
  36. PicDwgBeg    EQU    130        ;PicComment Kinds
  37. PicDwgEnd    EQU    131
  38. PolyBegin    EQU    160
  39. PolyEnd        EQU    161
  40. PolyIgnore    EQU    163
  41. PolySmooth    EQU    164
  42. PicPlyClo    EQU    165
  43. SetLineWidth    EQU    182
  44. ; ----------------------------------
  45. Frame        EQU    1        ;PolyVerbs
  46. Fill        EQU    2
  47. Close        EQU    4
  48. ; =======================================
  49. ; ------------  M A C R O  --------------
  50. ; ---------------------------------------
  51. MACRO    prExec    RoutineSelect    =
  52.     MOVE.L    #{RoutineSelect},-(SP)    ;routine selector on stack
  53.     DC.W    PrGlue            ;execute trap
  54.     |
  55. ; ---------------------------------------
  56. MACRO    ShortComment    Kind    =
  57.     MOVE.W    #{Kind},-(SP)
  58.     CLR.W    -(SP)
  59.     CLR.L    -(SP)
  60.     _PicComment
  61.     |
  62. ; ---------------------------------------
  63. MACRO    LongComment    Kind,Size,Hand    =
  64.     MOVE.W    #{Kind},-(SP)
  65.     MOVE.W    #{Size},-(SP)
  66.     MOVE.L    {Hand},-(SP)
  67.     _PicComment
  68.     |
  69. ; ---------------------------------------
  70. MACRO    CheckItm    MHandle,Item    =
  71.     MOVE.L    {MHandle}(A5),-(SP)
  72.     MOVE.W    {Item},-(SP)
  73.     ST    -(SP)            ;check
  74.     _CheckItem
  75.     |
  76. ; ---------------------------------------
  77. MACRO    UnChkItm    MHandle,Item    =
  78.     MOVE.L    {MHandle}(A5),-(SP)
  79.     MOVE.W    {Item},-(SP)
  80.     CLR    -(SP)            ;uncheck
  81.     _CheckItem
  82.     |
  83. ; =======================================
  84. ; --------- Register usage --------------
  85. PolyHand        EQU    A4
  86. ; -------------------------------------
  87.     BSR    InitGlobals    ;Do not rearrange the order of these subs
  88.     BSR    InitMac
  89.     BSR    GetHandles
  90.     BSR    SetMenus
  91.     BSR    SetWindow
  92.     BRA    NewPoly        ;init one
  93. ; ======================================
  94. Loop    _SystemTask
  95.     CLR.W    -(SP)
  96.     MOVE.W    #$FFFF,-(SP)        ;Every event
  97.     PEA    EVENTRECORD(A5)
  98.     _GetNextEvent
  99.     MOVE.B    (SP)+,D0
  100.     BNE.S    DoEvent
  101.     TST.W    whileDrawing(A5)        ;Check if we have to…
  102.     BNE.S    TrackLine        ;Idle line
  103.     BRA.S    Loop
  104.  
  105. DoEvent    MOVE.W    WHAT(A5),D0
  106.     CMP.W    #1,D0            ;is mousedown ? 
  107.     BEQ    MouseDown
  108.     CMP.W    #3,D0            ;is keydown ? 
  109.     BEQ    KeyDown
  110.     CMP.W    #6,D0            ;is update ?
  111.     BEQ    UpDate
  112.     CMP.W    #8,D0            ;is activate ?
  113.     BEQ    DoAct    
  114.     BRA.S    Loop            ;we don't support other events
  115. ; ==========================================
  116. TrackLine
  117.     PEA    CurPoint(A5)
  118.     _GetMouse
  119.     MOVE.L    CurPoint(A5),D0
  120.     CMP.L    OldPoint(A5),D0        ;Did we move since last time ?
  121.     BEQ.S    Loop            
  122.                     ;we are in XOR mode
  123.     MOVE.L    LastPoint(A5),-(SP)    ;start Pt
  124.     _MoveTo
  125.     MOVE.L    OldPoint(A5),-(SP)    ;overwrite old line
  126.     _LineTo
  127.     MOVE.L    LastPoint(A5),-(SP)    ;draw new line
  128.     _MoveTo
  129.     MOVE.L    CurPoint(A5),-(SP)
  130.     _LineTo
  131.     MOVE.L    CurPoint(A5),OldPoint(A5)    ;c'est la vie
  132.     BRA.S    Loop
  133. ; ------------------------------------------
  134. DoAct    MOVE.W    MODIFY(A5),D0
  135.     BTST    #0,D0            ;Activate or deactivate
  136.     BEQ.S    DeAct
  137.     MOVE.L    MESSAGE(A5),-(SP)
  138.     _SetPort
  139.     BSR    DimMenu            ;we only support copy menu
  140.     BSR    PutGrow
  141.     BRA    LOOP
  142. DeAct    BSR    ActMenu            ;Allow complete edit menu for DA
  143.     PEA    GrowBox(A5)
  144.     _EraseRect            ;clean it and
  145.     BSR    PutGrow            ;draw inactive
  146.     BRA    LOOP
  147. ; -----------------------------
  148. UpDate
  149.     MOVE.L    TheWind(A5),-(SP)
  150.     _BeginUpdate
  151.     TST.W    PolyDrawn(A5)        
  152.     BEQ.S    @0            ;branch if no poly
  153.     BSR    ReDraw            ;show poly
  154.     BRA.S    @1
  155. @0    TST.W    WhileDrawing(A5)
  156.     BEQ.S    @1            ;Exit if we are not either drawing
  157.     BSR    DrawPoly            ;Redraw part already drawn
  158.     MOVE.L    LastPoint(A5),-(SP)    ;redraw idle line    
  159.     _MoveTo
  160.     MOVE.L    OldPoint(A5),-(SP)
  161.     _LineTo
  162. @1    BSR    PutGrow
  163.     MOVE.L    TheWind(A5),-(SP)
  164.     _EndUpdate
  165.     BRA    LOOP
  166. ; ------------------------------
  167. MouseDown
  168.     CLR.W    -(SP)
  169.     MOVE.L    WHERE(A5),-(SP)
  170.     PEA    WINDOW(A5)
  171.     _FindWindow
  172.     MOVE.W    (SP)+,D0
  173.     MOVE.W    D0,D3            ;needed for zoom box
  174.     ADD.W    D0,D0
  175.     MOVE.W    WTABLE(PC,D0.W),D0
  176.     JMP    WTABLE(PC,D0.W)
  177. WTABLE    DC.W    LOOP-WTABLE
  178.     DC.W    DoMenu-WTABLE
  179.     DC.W    SysEvnt-WTABLE
  180.     DC.W    DoContent-WTABLE
  181.     DC.W    DoDrag-WTABLE
  182.     DC.W    DoGrow-WTABLE
  183.     DC.W    Loop-WTABLE
  184.     DC.W    DoZoom-WTABLE
  185.     DC.W    DoZoom-WTABLE
  186. ; --------------------------------
  187. KeyDown    CLR.L    -(SP)
  188.     MOVE.W    MESSAGE+2(A5),-(SP)
  189.     _MenuKey
  190.     MOVE.L    (SP)+,MENU(A5)
  191.     BRA.S    ExMenu
  192. ; --------------------------------
  193. DoMenu
  194.     CLR.L    -(SP)
  195.     MOVE.L    WHERE(A5),-(SP)
  196.     _MenuSelect
  197.     MOVE.L    (SP)+,MENU(A5)
  198. ExMenu    CLR.W    -(SP)
  199.     _HiliteMenu            ;Hilite off
  200.     MOVE.W    MENU(A5),D0
  201.     CMP.W    #4,D0            ;is a submenu ?
  202.     BLE.S    @0
  203.     SUB.W    #'A'-4-1,D0    ;Allign Submenu item-60 (65-4-1)
  204. @0    ADD.W    D0,D0
  205.     MOVE.W    MTABLE(PC,D0.W),D0
  206.     JMP    MTABLE(PC,D0.W)
  207. MTABLE    DC.W    LOOP-MTABLE        ;Menus
  208.     DC.W    DoMela-MTABLE
  209.     DC.W    DoFile-MTABLE
  210.     DC.W    DoEdit-MTABLE
  211.     DC.W    DoDo-MTABLE    
  212.     DC.W    DoPensize-MTABLE        ;submenus
  213.     DC.W    DoPat-MTABLE
  214.     DC.W    DoPenscale-MTABLE
  215. ; -----------------------------
  216. DoContent
  217.     CLR.L    -(SP)
  218.     _FrontWindow
  219.     MOVE.L    (SP)+,D0
  220.     CMP.L    WINDOW(A5),D0
  221.     BEQ.S    @0            ;Already in front
  222.     MOVE.L    WINDOW(A5),-(SP)
  223.     _SelectWindow
  224.     
  225. @0    BSR    ChkDoubClick        ;set DoubleClick(A5) accordingly
  226.     MOVE.L    WHERE(A5),MousLoc(A5)
  227.     PEA    MousLoc(A5)
  228.     _GlobalToLocal
  229.     
  230.     TST.W    PolyDrawn(A5)        ;do we have a poly yet ?
  231.     BNE    Loop            ;yes, no action implemented
  232.     TST.W    whileDrawing(A5)        ;No, is it initialized yet ?
  233.     BNE    AddPoint            ;yes, one more line for the poly
  234.     BRA    PolyInit            ;No, start a new one
  235. ; ----------------------------------------
  236. DoDrag    MOVE.L    WINDOW(A5),-(SP)
  237.     MOVE.L    WHERE(A5),-(SP)
  238.     PEA    WBounds(A5)
  239.     _DragWindow
  240.     BRA    LOOP
  241. ; ---------------------------------------
  242. DoGrow    CLR.L    -(SP)
  243.     MOVE.L    WINDOW(A5),-(SP)
  244.     MOVE.L    WHERE(A5),-(SP)
  245.     PEA    WSize(A5)
  246.     _GrowWindow
  247.     MOVE.L    (SP)+,D0
  248.     BEQ    LOOP            ;Laizy, if not grown
  249.  
  250.     MOVE.L    WINDOW(A5),-(SP)
  251.     MOVE.L    D0,-(SP)
  252.     ST    -(SP)
  253.     _SizeWindow
  254.     PEA    GrowBox(A5)
  255.     _EraseRect            ;Erase it and
  256.     PEA    GrowBox(A5)        ;put it in the update rgn
  257.     _InvalRect    
  258.     
  259. ResetWnd    BSR    CalcGrow
  260.     BSR    ClipWind
  261.     BSR    PutGrow
  262.     BRA    LOOP    
  263. ; -------------------------------------
  264. DoZoom    CLR.W    -(SP)
  265.     MOVE.L    WINDOW(A5),-(SP)
  266.     MOVE.L    WHERE(A5),-(SP)
  267.     MOVE.W    D3,-(SP)            ;PartCode in or out
  268.     _TrackBox
  269.     TST.W    (SP)+
  270.     BEQ    LOOP
  271.     MOVE.L    WINDOW(A5),A0
  272.     PEA    PortRect(A0)
  273.     _EraseRect
  274.     CLR.W    -(SP)
  275.     MOVE.L    WINDOW(A5),-(SP)
  276.     MOVE.W    D3,-(SP)            ;PartCode in or out
  277.     SF    -(SP)
  278.     _ZoomWindow
  279.     BRA    ResetWnd
  280. ; ----------------------------------------
  281. SysEvnt    PEA    EVENTRECORD(A5)        ;make system happy
  282.     MOVE.L    WINDOW(A5),-(SP)
  283.     _SystemClick
  284.     BRA    LOOP
  285. ; ----------------------------------------
  286. PolyInit
  287.     MOVE.L    MousLoc(A5),-(SP)        ;Start poly
  288.     _Moveto
  289.     MOVE.W    #10,-(SP)        ;XOR mode while drawing poly
  290.     _PenMode
  291.     MOVE.L    #$10001,-(SP)
  292.     _PenSize                ;Pen 1,1
  293.     MOVE.W    #1,NumPoints(A5)        ;First point
  294.     MOVE.L    (PolyHand),A0
  295.     MOVE.L    MousLoc(A5),(A0)        ;write it in the list
  296.     MOVE.W    #4,BytesWritten(A5)
  297.     ST    whileDrawing(A5)        ;follow mouse movement with a line
  298.     MOVE.L    MousLoc(A5),LastPoint(A5)    ;init points
  299.     MOVE.L    MousLoc(A5),OldPoint(A5)
  300.     BRA    Loop
  301. ; -----------------------------------------
  302. AddPoint    
  303.     TST.W    DoubleClick(A5)        ;user wants to close the poly ?
  304.     BNE    ClosePoly
  305.     MOVE.L    LastPoint(A5),-(SP)    ;clear last line
  306.     _MoveTo
  307.     MOVE.L    OldPoint(A5),-(SP)
  308.     _LineTo
  309.     _PenNormal            ;Reset pen
  310.     MOVE.L    LastPoint(A5),-(SP)    ;add new line
  311.     _MoveTo
  312.     MOVE.L    MousLoc(A5),-(SP)
  313.     _LineTo
  314.     MOVE.W    #10,-(SP)        ;put back XOR mode
  315.     _PenMode
  316.     BSR    DoAdd            ;put new point into the list
  317.     CMP.W    #32760,BytesWritten(A5)    ;Do not write past block
  318.     BPL    ClosePoly        ;force to close in case
  319.     BRA    Loop
  320. ; ------------------------------------------
  321. ; Pack 'MousLoc' into compressed poly data list :
  322. ; A negative word signals a short delta; a word as follows…
  323. ; / bit 15 always set / bits 14-8 = dy (-64,63) / bits 7-Ø = dx (-128,127)/
  324. ; A positive word signals a 4 bytes point (Y & X) as usual
  325. ; WARNING(¿): this scheme won't work if high bit of point is negative
  326. ; (if a Y becomes <Ø a point will be interpreted as a short offset)
  327. ; -------------------------------------------
  328. DoAdd    ADDQ.W    #1,NumPoints(A5)        ;one more point
  329.     MOVE.L    (PolyHand),A0        ;Pointer in A0
  330.     ADDA.W    BytesWritten(A5),A0    ;get to mark
  331.  
  332.     MOVE.W    MousLoc(A5),D0        ;current Y
  333.     SUB.W    LastPoint(A5),D0        ;D0 = Delta Y
  334.     CMP.W    #63,D0            ;Dy must be in the range
  335.     BGT.S    LongPoint        ;doesn't fit
  336.     CMP.W    #-64,D0
  337.     BMI.S    LongPoint
  338.                     ;Y fits, now check X
  339.     MOVE.W    MousLoc+2(A5),D1        ;current X
  340.     SUB.W    LastPoint+2(A5),D1    ;D1 = Delta X
  341.     CMP.W    #127,D1            ;Dy in a signed byte range ?
  342.     BGT.S    LongPoint
  343.     CMP.W    #-128,D1
  344.     BMI.S    LongPoint
  345. WordPoint                ;Word format Point (compressed)
  346.     ADD.W    #2,BytesWritten(A5)    ;only 2 bytes for a short offset
  347.     BSET    #7,D0            ;force a negative word to signal
  348.     MOVE.B    D0,(A0)+            ;write Y offset
  349.     MOVE.B    D1,(A0)            ;write X offset
  350.     BRA.S    AddDone
  351. LongPoint                ;Long format (normal)
  352.     ADD.W    #4,BytesWritten(A5)    ;not an offset, a Point
  353.     MOVE.L    MousLoc(A5),(A0)        ;always positive in our plane    
  354. AddDone    
  355.     MOVE.L    MousLoc(A5),LastPoint(A5)    ;update
  356.     MOVE.L    MousLoc(A5),OldPoint(A5)
  357.     RTS
  358. ; ------------------------
  359. ClosePoly
  360.     ST    PolyDrawn(A5)        ;Poly is now completed
  361.     CLR.W    whileDrawing(A5)        ;we are through
  362.     _PenNormal            ;reset mode and size
  363.     MOVE.L    DoHand(A5),-(SP)
  364.     MOVE.W    #1,-(SP)
  365.     _EnableItem            ;allow unsmooth/smooth
  366.     MOVE.L    FileHand(A5),-(SP)
  367.     MOVE.W    #3,-(SP)
  368.     _EnableItem            ;and print
  369.     
  370.     MOVE.L    (PolyHand),A0        ;Pointer in A0
  371.     MOVE.L    (A0),MousLoc(A5)        ;save extra code simulating a click
  372.     BSR    DoAdd            ;at last point (MousLoc) = first
  373.     _OpenRgn            ;WARNING :(¿) should make sure our poly is not 
  374.     BSR    DrawPoly            ;too big to fit in a region.
  375.     MOVE.L    RgnHand(A5),-(SP)        ;if it doesn't fit, we are dead
  376.     _CloseRgn
  377.     BSR    SetPen
  378.     BSR    CleanWind
  379.     BSR    ReDraw            ;show poly            
  380.     BRA    Loop
  381. ; =============================
  382. DoMela
  383.     CMPI.W    #2,MENU+2(A5)
  384.     BGT    @1
  385.                     ;Show about dialog
  386.     CLR.L    -(SP)            ;space for result
  387.     MOVE.W    #256,-(SP)        ;ID
  388.     CLR.L    -(SP)            ;NIL storage
  389.     MOVE.L    #-1,-(SP)        ;in front
  390.     _GetNewDialog
  391.     MOVE.L    (SP)+,A2
  392. @0    CLR.L    -(SP)
  393.     PEA    ItmHit(A5)
  394.     _ModalDialog
  395.     CMP.W    #1,ITMHIT(A5)
  396.     BNE.S    @0
  397.     MOVE.L    A2,-(SP)
  398.     _DisposDialog
  399.     BRA    LOOP
  400.     
  401. @1    MOVE.L    MelaHand(A5),-(SP)    ;Get DA
  402.     MOVE.W    MENU+2(A5),-(SP)
  403.     PEA    DskName(A5)
  404.     _GetItem
  405.     CLR.W    -(SP)
  406.     PEA    DskName(A5)
  407.     _OpenDeskAcc
  408.     MOVE.W    (SP)+,D0
  409.     BRA    Loop
  410. ; ---------------------------------
  411. DoFile
  412.     MOVE.W    MENU+2(A5),D0        ;Item Num
  413.     ADD.W    D0,D0
  414.     MOVE.W    M1TAB(PC,D0.W),D0
  415.     JMP    M1TAB(PC,D0.W)
  416. M1TAB    DC.W    LOOP-M1TAB
  417.     DC.W    NewPoly-M1TAB
  418.     DC.W    PageSetup-M1TAB
  419.     DC.W    Print-M1TAB
  420.     DC.W    LOOP-M1TAB        ;Laser Pen Menu
  421.     DC.W    Quit-M1TAB
  422. ;-----------------------------------
  423. DoEdit    
  424.     CLR.L    -(SP)            ;Check if DA in front
  425.     _FrontWindow
  426.     MOVE.L    (SP)+,A0
  427.     CMP.L    TheWind(A5),A0
  428.     BEQ    DoScrap            ;branch if our wind in front
  429.     CLR.B    -(SP)            ;System Wind Frontmost            
  430.     MOVE.W    MENU+2(A5),-(SP)
  431.     SUBQ.W    #1,(SP)            ;balance different numbering
  432.     _SysEdit
  433.     TST.B    (SP)+            ;get rid of bool
  434.     BRA    LOOP
  435. ;------------------------------
  436. NewPoly
  437.     CLR.W    PolyDrawn(A5)        ;clear poly
  438.     CLR.W    WhileDrawing(A5)
  439.     CLR.W    NumPoints(A5)
  440.     CLR.W    Liscio(A5)        ;no poly, no smooth
  441.     MOVE.L    DoHand(A5),-(SP)        ;Menu Handle
  442.     MOVE.W    #1,-(SP)
  443.     PEA    'Smooth'
  444.     _SetItem                ;reset
  445.     MOVE.L    DoHand(A5),-(SP)
  446.     MOVE.W    #1,-(SP)
  447.     _DisableItem            ;no smooth menu and
  448.     MOVE.L    FileHand(A5),-(SP)    ;no print active
  449.     MOVE.W    #3,-(SP)
  450.     _DisableItem
  451.     BSR    CleanWind
  452.     BRA    Loop
  453. ;------------------------------
  454. PageSetup
  455.     prExec    PrOpen            ;open the driver
  456.     BSR    CheckErr            ;driver ok
  457.     CLR.W    -(SP)            ;Style Dialog
  458.     MOVE.L    PrintRec(A5),-(SP)
  459.     prExec    PrStlDialog
  460.     MOVE.W    (SP)+,D0            ;forget it
  461.     prExec    PrClose
  462.     BRA    Loop
  463. ; =========================================
  464. Print
  465.     MOVE.L    D3,-(SP)            ;save D3
  466.     PEA    SavePort(A5)        ;Save current port
  467.     _GetPort
  468.     
  469.     prExec    PrOpen            ;open the driver
  470.     BSR    CheckErr            ;driver opened successfully ?
  471.  
  472.     CLR.W    -(SP)            ;Job Dialog
  473.     MOVE.L    PrintRec(A5),-(SP)    
  474.     prExec    PrJobDialog
  475.     MOVE.W    (SP)+,D0
  476.     BEQ    PrintDon            ;canceled?
  477.     
  478.     BSR    OroCurs            ;put watch curs    
  479.     CLR.L    -(SP)            ;Open Print Port
  480.     MOVE.L    PrintRec(A5),-(SP)
  481.     CLR.L    -(SP)
  482.     CLR.L    -(SP)
  483.     prExec    PrOpenDoc
  484.     MOVE.L    (SP)+,PrintPort(A5)
  485.     BSR    CheckErr            ;problems?
  486.     
  487.     MOVE.L    PrintRec(A5),A0        ;Initialize New Graph Port
  488.     MOVE.L    (A0),A0
  489.     PEA    prInfo+rpage(A0)        
  490.     _ClipRect
  491.     
  492.     MOVEQ    #1,D3            ;assume Spool
  493.     MOVE.L    PrintRec(A5),A0
  494.     MOVE.L    (A0),A0
  495.     TST.B    prJob+bjDocLoop(A0)    ;Check if Draft or Spool
  496.     BNE.S    @1
  497.     MOVE.W    prJob+iCopies(A0),D3    ;Set Num copies if Draft
  498. @1    SUBQ.W    #1,D3            ;for DBRA
  499.     
  500. PageLoop                    
  501.     MOVE.L    PrintPort(A5),-(SP)    ;get ready to draw
  502.     CLR.L    -(SP)            
  503.     prExec    PrOpenPage        ;new page
  504.     BSR    CheckErr            ;are we ok?
  505.     
  506.     MOVE.L    CurPen(A5),-(SP)        ;Set size and…
  507.     _PenSize
  508.     MOVE.L    CommentHand(A5),A1    ;scaling
  509.     MOVE.L    (A1),A0            ;deference handle
  510.     MOVE.W    #12,(A0)+        ;numerator = 72/6 and…
  511.     MOVE.W    CurScale(A5),(A0)        ;denominator in dpi/6        
  512.     LongComment    SetLineWidth,4,A1
  513.     
  514.     BSR    MakePoly            ;do it
  515.  
  516.     MOVE.L    PrintPort(A5),-(SP)
  517.     prExec    PrClosePage        ;page done
  518.     BSR    CheckErr
  519.     
  520.     DBRA    D3,PageLoop        ;next page
  521.     
  522.     MOVE.L    PrintPort(A5),-(SP)
  523.     prExec    PrCloseDoc        ;document done
  524.     BSR    CheckErr
  525.     
  526.     MOVE.L    PrintRec(A5),A0
  527.     MOVE.L    (A0),A0
  528.     TST.B    prJob+bjDocLoop(A0)    ;Check if Draft or Spool
  529.     BEQ.S    PrintDon            ;Branch if draft
  530.     
  531.     MOVE.L    PrintRec(A5),-(SP)    ;spool to printer
  532.     CLR.L    -(SP)
  533.     CLR.L    -(SP)
  534.     CLR.L    -(SP)
  535.     PEA    PrStatus(A5)
  536.     prExec    PrPicFile        ;print spool file
  537.     BSR    CheckErr
  538.     
  539. PrintDon    prExec    PrClose            ;close driver
  540.     MOVE.L    SavePort(A5),-(SP)
  541.     _SetPort                ;restore port
  542.     MOVE.L    (SP)+,D3            ;register and
  543.     _InitCursor            ;arrow curs            
  544.     BRA    Loop
  545. ; --------------------
  546. CheckErr    CLR.W    -(SP)            ;WARNING (¿)
  547.     prExec    PrError            ;if an error occurs we have no handler
  548.     MOVE.W    (SP)+,D0            ;Err code in D0
  549.     BNE    Error            ;this just goes to the finder
  550.     RTS
  551. ; ===============================
  552. Quit    _ExitToShell            ;ciao
  553. ; ===============================
  554. DoScrap
  555.     TST.W    PolyDrawn(A5)
  556.     BEQ    Loop            ;nothing to clip
  557.     
  558.     PEA    WRect(A5)        ;(¿) Not a correct rect
  559.     _ClipRect            ;it's here just to save code
  560.     CLR.L    -(SP)
  561.     PEA    WRect(A5)        ;(¿) should use a better rect
  562.     _OpenPicture            ;(¿) Do we have enough memory for a pict?
  563.     MOVE.L    (SP)+,A2            ;PicHandle
  564.     ShortComment    PicDwgBeg    ;yes, it's the format you know        
  565.     BSR    MakePoly            ;do it
  566.     ShortComment    PicDwgEnd
  567.     _ClosePicture
  568.     BSR    ClipWind            ;restore clip
  569.  
  570.     CLR.L    -(SP)
  571.     _ZeroScrap
  572.     MOVE.L    (SP)+,D0
  573.     BNE    Error
  574.     MOVE.L    A2,A0
  575.     _GetHandleSize            ;how big is the pict
  576.     CLR.L    -(SP)
  577.     MOVE.L    D0,-(SP)            ;lenght
  578.     MOVE.L    #'PICT',-(SP)        ;ResType
  579.     MOVE.L    (A2),-(SP)        ;Ptr Pict
  580.     _PutScrap            ;put it down
  581.     MOVE.L    (SP)+,D0
  582.     BNE    Error
  583.     MOVE.L    A2,-(SP)
  584.     _KillPicture            ;Get rid of it
  585.     BRA    Loop
  586. ; -------------------------------
  587. DoDo                    ;Smooth or unsmoooth
  588.     MOVE.L    DoHand(A5),-(SP)        ;Menu Handle
  589.     MOVE.W    #1,-(SP)            ;item num
  590.     NOT.W    Liscio(A5)        ;set & check Smooth flag
  591.     BEQ.S    @0            ;branch accordingly
  592.     LEA    DrawSmooth(PC),A3        ;routine to call in A3
  593.     PEA    'Unsmooth'        ;load proper name
  594.     BRA.S    @1
  595. @0    LEA    DrawPoly(PC),A3        ;no smooth
  596.     PEA    'Smooth'            
  597. @1    _SetItem    
  598.     _OpenRgn
  599.     JSR    (A3)        ;WARNING :(¿) should make sure our poly is not
  600.     MOVE.L    RgnHand(A5),-(SP)        ;too big to fit in a region
  601.     _CloseRgn            ;if it doesn't fit, we are dead
  602.     BSR    CleanWind
  603.     BSR    ReDraw
  604.     BRA    Loop
  605. ; ===============================
  606. DoPensize
  607.     UnChkItm    PenHand,CurPen(A5)    ;uncheck old
  608.     MOVE.W    MENU+2(A5),CurPen(A5)    ;v
  609.     MOVE.W    MENU+2(A5),CurPen+2(A5)    ;h
  610.     CheckItm    PenHand,CurPen(A5)    ;check new
  611.     TST.W    PolyDrawn(A5)
  612.     BEQ    Loop
  613.     BSR    SetPen
  614.     BSR    CleanWind
  615.     BSR    Redraw
  616.     BRA    Loop
  617. ;------------------------------
  618. DoPat
  619.     UnChkItm    FpatHand,ChkPat(A5)    ;uncheck old
  620.     MOVE.W    MENU+2(A5),ChkPat(A5)
  621.     CheckItm    FpatHand,ChkPat(A5)    ;check new
  622.  
  623.     MOVE.W    MENU+2(A5),D0
  624.     SUBQ.W    #1,D0
  625.     ADD.W    D0,D0
  626.     MOVE.W    PatTab(PC,D0.W),CurPat(A5)    ;get offset constant to PAT
  627.     TST.W    PolyDrawn(A5)
  628.     BEQ    Loop
  629.     BSR    CleanWind
  630.     BSR    ReDraw
  631.     BRA    Loop
  632. PatTab    DC.W    -8            ;White
  633.     DC.W    -32            ;LtGray
  634.     DC.W    -24            ;Gray
  635.     DC.W    -40            ;DkGray
  636.     DC.W    -16            ;Black
  637. ; --------------------------------
  638. DoPenscale
  639.     UnChkItm    PscaleHand,Chkscale(A5)    ;uncheck old
  640.     MOVE.W    MENU+2(A5),Chkscale(A5)
  641.     CheckItm    PscaleHand,Chkscale(A5)    ;check new
  642.     MOVE.W    MENU+2(A5),D0
  643.     SUBQ.W    #1,D0
  644.     ADD.W    D0,D0
  645.     MOVE.W    SclTab(PC,D0.W),CurScale(A5) ;get scale factor
  646.     BRA    Loop
  647. SclTab                    ;unsign byte values (0-255)
  648.     DC.W    12            ;  72/6
  649.     DC.W    25            ; 150/6
  650.     DC.W    50            ; 300/6
  651.     DC.W    100            ; 600/6
  652.     DC.W    200            ;1200/6
  653. ; =================================
  654. SetPen
  655.     TST.W    WhileDrawing(A5)        ;don't change pen if drawing poly
  656.     BNE.S    @0
  657.     MOVE.L    CurPen(A5),-(SP)
  658.     _PenSize
  659. @0    RTS
  660. ; --------------------------------    
  661. Redraw                    ;no poly to work with
  662.     TST.W    CurPat(A5)        ;is our poly filled ?
  663.     BEQ.S    @0            ;No fill if CurPat=Ø
  664.     BSR    FillPoly
  665. @0    TST.W    Liscio(A5)        ;is poly smoothed ?
  666.     BNE.S    DrawSmooth
  667.  
  668. DrawPoly
  669.     MOVE.W    NumPoints(A5),D4        ;Total num of points
  670.     SUBQ.W    #2,D4            ;sub 1 for DBRA and 1 for _Moveto
  671.     BGT.S    @0            ;check reasonable poly (>2 points)
  672.     RTS                ;return if not to consider a poly
  673. @0    MOVE.L    PolyHand    ,A0        ;No surprise
  674.     _HLock                ;Line and LineTo can cause relocation
  675.     BNE    Error
  676.     MOVE.L    (PolyHand),A3        ;Pointer to Poly data
  677.     MOVE.L    (A3)+,-(SP)        ;first point
  678.     _MoveTo
  679. NextLine
  680.     TST.W    (A3)            ;Check for bit 15 (sign)
  681.     BPL.S    LongPt            ;IF set do Long ELSE do Short
  682.  
  683. ShortPt    MOVE.B    (A3)+,D1            ;dY: a signed 7 bits offset
  684.     BTST    #6,D1            ;Test sign bit:a negative offset ?
  685.     BNE.S    @0            ;yes, flag bit can stay
  686.     BCLR    #7,D1            ;else (if positive) clear it
  687. @0    EXT.W    D1            ;DY as a word
  688.     SWAP    D1            ;in hi word D1 now
  689.     MOVE.B    (A3)+,D1            ;signed byte dx
  690.     EXT.W    D1            ;dx in low word
  691.     MOVE.L    D1,-(SP)            ;offset on stack
  692.     _Line                ;draw to
  693.     BRA.S    NxLn
  694.  
  695. LongPt    MOVE.L    (A3)+,-(SP)
  696.     _LineTo                ;a point
  697. NxLn    DBRA    D4,NextLine
  698.  
  699.     MOVE.L    PolyHand    ,A0        ;free again
  700.     _HUnLock
  701.     BNE    Error
  702.     RTS
  703. ; ---------------------------
  704. DrawSmooth    
  705.     BSR    UnPackPoly        ;we need normal points to work
  706.     MOVE.L    PolyBuffer(A5),A0        ;our temporary poly
  707.     _HLock
  708.     BNE    Error
  709.     MOVE.L    PolyBuffer(A5),A0
  710.                     ;Emulating a High-Level call
  711.     MOVE.W    NumPoints(A5),-(SP)    ;First param     
  712.     MOVE.L    (A0),-(SP)        ;second, a Ptr to points list        
  713.     BSR    SmoothPoly        ;fortissimo
  714.     
  715.     MOVE.L    PolyBuffer(A5),A0
  716.     _HUnLock                ;free again
  717.     BNE    Error
  718.     RTS
  719. ; ===================================================================
  720. ; SmoothPoly (NumPt:INTEGER; PtrPolyList:PTR)
  721. ; (¿) Implementation good for poly side<1024 pixels of length
  722. ; The resulting smoothed polygon closely resembles the laser output
  723. ; -------------------------------------------------------------------
  724. LineTo        EQU    $91        ;trap num
  725. ; ----------------------------------
  726. ; ---------- Stack Frame -----------
  727. ; ----------------------------------
  728. NumPt        EQU    12
  729. PtrList        EQU    8        
  730. ParamBytes    EQU    6
  731. ;
  732. A        EQU    -2
  733. B        EQU    -4
  734. Av        EQU    -6
  735. Bv        EQU    -8
  736. X        EQU    -10
  737. Y        EQU    -12
  738. Line        EQU    -16
  739. OldW        EQU    -18
  740. OldQ        EQU    -20
  741. ;
  742. Locals        EQU    -20
  743. ; ====================================================
  744. ; The following is a Basic translation of the algorithm 
  745. ; Comments in the Asm source refer to these integer variables
  746. ; Note that the two version slightly differs where necessary
  747. ; P(c,n) is a bidimensional array of points:
  748. ; P(0,n)=Y P(1,n)=X ; n=point index
  749. ; ----------------------------------------------------
  750. ; X1=P(1,1)-P(1,0):Y1=P(0,1)-P(0,0)
  751. ; X=X1\2+P(1,0):Y=Y1\2+P(0,0)
  752. ; MOVETO X,Y
  753. ; FOR j=1 TO NumPt
  754. ;    X0=X1:Y0=Y1
  755. ;    X1=P(1,j+1)-P(1,j):Y1=P(0,j+1)-P(0,j)
  756. ;    T=(ABS(X1+X0)+ABS(Y1+Y0))\8
  757. ;    IF T<2 THEN T=2
  758. ;    Z=T*T*2:Du=T+1
  759. ;   FOR n=0 TO T
  760. ;    Du=Du-1:Q=n*n:w=Du*Du
  761. ;    A=(Q*X1-w*X0)/Z+P(1,j)
  762. ;    B=(Q*Y1-w*Y0)/Z+P(0,j)
  763. ;    LINETO A,B
  764. ;   NEXT
  765. ; NEXT
  766. ; LINETO X,Y
  767. ; ==================================
  768. SmoothPoly                ;If called from hi level think of it
  769.     LINK    A6,#Locals        ;like a ToolBox procedure
  770.     MOVEM.L    A1-A4/D0-D7,-(SP)        ;save the world
  771.     
  772.     MOVE.L    PtrList(A6),A4        ;A4 point list Ptr
  773.     MOVE.W    #LineTo,D0        ;Trap num for LineTo
  774.     _GetTrapAddress            ;save some cycle
  775.     MOVE.L    A0,A3            ;store in A3 for later use
  776.     CLR.L    Bv(A6)            ;clear last drawn point
  777.     
  778.     MOVE.L    (A4),D4            ;First Pt
  779.     MOVE.L    4(A4),D5            ;second Pt
  780.     SUB.W    D4,D5            ;X1
  781.     MOVE.W    D5,D1            ;safe in D1
  782.     SWAP    D4            ;push y in low word
  783.     SWAP    D5
  784.     SUB.W    D4,D5            ;Y1
  785.     MOVE.W    D5,D0            ;safe in D0
  786.     ASR.W    #1,D1            ;divs by 2 with no sign loss
  787.     ASR.W    #1,D0
  788.     ADD.W    D4,D0            ;D0=Y+(Y2-Y1)/2
  789.     ADD.W    2(A4),D1            ;D1=X+(X2-X1)/2
  790.     MOVE.W    D0,Y(A6)            ;First point recorded for closing
  791.     MOVE.W    D1,X(A6)
  792.     MOVE.W    D1,-(SP)
  793.     MOVE.W    D0,-(SP)
  794.     _MoveTo                
  795.     SUBQ.W    #1,NumPt(A6)        ;ready to start        
  796. NextPoint
  797.     MOVE.L    D5,D4            ;Y0=Y1 : X0=X1
  798.     ADDQ.L    #4,A4            ;Current=Next
  799.     MOVE.L    4(A4),D5            ;Next Point in D5
  800.     SUB.W    2(A4),D5            ;X1=NextX-CurX
  801.     MOVE.W    D5,D6            ;safe in D6
  802.     SWAP    D5            ;push Y down
  803.     SUB.W    (A4),D5            ;Y1=NextY-CurY
  804.     MOVE.W    D5,D0            ;safe in D0
  805. ;                Calc num iteration now (T) ------------
  806.     ADD.W    D4,D0            ;D0=Y0+Y1
  807.     BPL.S    @1
  808.     NEG.W    D0            ;ABS
  809. @1    SWAP    D4            ;x in low word
  810.     ADD.W    D4,D6            ;D6=X0+X1
  811.     BPL.S    @2
  812.     NEG.W    D6            ;ABS
  813. @2    SWAP    D4            ;y back in low
  814.     
  815.     ADD.W    D0,D6            ;D6=(D0^2+D6^2)
  816.     LSR.W    #3,D6            ;T=D6\8 (step)
  817.     CMP.W    #2,D6            ;T=>2 at least
  818.     BPL.S    @0
  819.     MOVEQ    #2,D6            ;T=D6
  820. @0    MOVE.W    D6,D7
  821.     MULU    D7,D7            ;T*T
  822.     LSL.W    #1,D7            ;Z=D7 (T*T*2)
  823.     MOVEQ    #0,D3            ;n=0
  824.  
  825.     MOVE.W    D6,D0            ;init values
  826.     ADDQ.W    #1,D0
  827.     MULU    D0,D0
  828.     MOVE.W    D0,OldW(A6)
  829.     MOVE.W    #1,OldQ(A6)
  830. Curva
  831.     MOVE.W    D6,D0            ;Calc W (T*T), avoiding slow MULU
  832.     ADD.W    D0,D0        
  833.     ADDQ.W    #1,D0
  834.     SUB.W    D0,OldW(A6)        ;W=(OldW)-2T+1
  835.     MOVE.W    OldW(A6),D0
  836.  
  837.     MOVE.W    D3,D1            ;Calc Q (n*n), avoiding slow MULU
  838.     ADD.W    D1,D1        
  839.     SUBQ.W    #1,D1
  840.     ADD.W    D1,OldQ(A6)        ;Q=(OldQ)+2n-1
  841.     MOVE.W    OldQ(A6),D1
  842.     
  843.     ADDQ.W    #1,D3            ;n=n+1
  844.  
  845.     MOVE.W    D0,D2            ;Calc B ------
  846.     MULS    D4,D2            ;Y0*W
  847.     MOVE.L    D2,A2
  848.     MOVE.W    D1,D2
  849.     MULS    D5,D2            ;Y1*Q
  850.     SUB.L    A2,D2
  851.     DIVS    D7,D2            ;/Z
  852.     ADD.W    (A4),D2            ;+ CurPt Y
  853.     MOVE.W    D2,B(A6)            ;safe
  854.     
  855.     SWAP    D4            ;push Xs down
  856.     SWAP    D5
  857.  
  858.     MOVE.W    D0,D2            ;Calc A ------
  859.     MULS    D4,D2            ;X0*W
  860.     MOVE.L    D2,A2
  861.     MOVE.W    D1,D2
  862.     MULS    D5,D2            ;X1*Q
  863.     SUB.L    A2,D2
  864.     DIVS    D7,D2            ;/Z
  865.     ADD.W    2(A4),D2            ;+ CurPt X
  866.     MOVE.W    D2,A(A6)            ;save
  867.     SWAP    D4
  868.     SWAP    D5
  869.     
  870.     CMP.W    Av(A6),D2    ;did we move? (over the unit)
  871.     BNE.S    @0        ;much faster to check it here, than go 
  872.     MOVE.W    B(A6),D2        ;through the ROM with a useless Lineto
  873.     CMP.W    Bv(A6),D2
  874.     BEQ.S    @1
  875.     
  876. @0    MOVE.L    B(A6),-(SP)
  877.     JSR    (A3)            ;LineTo
  878.     MOVE.L    B(A6),Bv(A6)
  879. @1    DBRA    D6,Curva
  880.  
  881.     SUBQ.W    #1,NumPt(A6)
  882.     BGT    NextPoint
  883.  
  884. Done    MOVE.L    Y(A6),-(SP)        ;back to first point
  885.     JSR    (A3)            ;LineTo
  886.     
  887.     MOVEM.L    (SP)+,A1-A4/D0-D7        ;restore the world
  888.     UNLK    A6
  889.     MOVE.L    (SP)+,A0            ;RTS
  890.     ADDQ    #ParamBytes,SP
  891.     JMP    (A0)            ;back home
  892. ; ---------------------------------
  893. UnPackPoly
  894.     MOVE.L    PolyBuffer(A5),A0        ;copy the poly here
  895.     MOVE.L    (A0),A0            ;Ptr to temporary space
  896.     MOVE.W    NumPoints(A5),D0
  897.     MOVE.W    BytesWritten(A5),D1
  898.     MOVE.L    (PolyHand),A1        ;Ptr to packed poly in A1
  899.     MOVE.L    (A1)+,(A0)+        ;first point
  900.     SUBQ.W    #1,D0            ;one pt processed
  901.     MOVE.L    (A1),-4(A1,D1.W)        ;add 2nd pt to the end of list
  902. Spacca    TST.W    (A1)            ;Check if short or long point
  903.     BMI.S    @0
  904.     MOVE.L    (A1)+,(A0)+        ;nothing to unpack
  905.     DBRA    D0,Spacca
  906.     BRA.S    SpacDon
  907. @0    MOVE.L    -4(A0),(A0)        ;point to add the offset to
  908.     MOVE.B    (A1)+,D1            ;dY: a signed 7 bits offset
  909.     BTST    #6,D1            ;a negative offset ?
  910.     BNE.S    @1            ;yes, flag bit can stay
  911.     BCLR    #7,D1            ;positive: clear flag bit
  912. @1    EXT.W    D1            ;DY as a word
  913.     ADD.W    D1,(A0)+
  914.     MOVE.B    (A1)+,D1            ;signed byte dx
  915.     EXT.W    D1            ;dx in low word
  916.     ADD.W    D1,(A0)+
  917.     DBRA    D0,Spacca
  918. SpacDon    RTS
  919. ; ========================================================
  920. FillPoly
  921.     MOVE.L    RgnHand(A5),-(SP)        ;Our Handle        
  922.     MOVE.W    CurPat(A5),D0        ;Offset to pat
  923.     MOVE.L    (A5),A0            ;Ptr to QD's Globals        
  924.     PEA    0(A0,D0.W)        ;fill it with Current Pat
  925.     _FillRgn
  926.     RTS
  927. ;-------------------------------
  928. CleanWind
  929.     MOVE.L    TheWind(A5),A0
  930.     PEA    PortRect(A0)
  931.     _EraseRect
  932.     BSR    PutGrow            ;show it
  933.     RTS
  934. ; -------------------------------
  935. ClipWind    
  936.     MOVE.L    TheWind(A5),A0
  937.     PEA    PortRect(A0)
  938.     _ClipRect
  939.     RTS
  940. ; -------------------------------
  941. PutGrow    
  942.     MOVE.L    #$10001,-(SP)
  943.     _PenSize                ;Use pen 1,1 to draw
  944.     MOVE.L    TempRgn(A5),-(SP)        ;save
  945.     _GetClip
  946.     PEA    GrowBox(A5)        ;only the box
  947.     _ClipRect
  948.     MOVE.L    TheWind(A5),-(SP)
  949.     _DrawGrowIcon
  950.     MOVE.L    TempRgn(A5),-(SP)        ;put back
  951.     _SetClip
  952.     BSR    SetPen            ;restore pen
  953.     RTS
  954. ; -------------------------------
  955. CalcGrow
  956.     MOVE.L    TheWind(A5),A0
  957.     LEA    GrowBox(A5),A1        ;Recalculate new GrowBox
  958.     MOVE.L    PortRect+4(A0),(A1)    ;push bottom right point of window
  959.     SUB.W    #15,(A1)+        ;make Top left box
  960.     SUB.W    #15,(A1)+
  961.     MOVE.L    PortRect+4(A0),(A1)    ;and bottom right
  962.     RTS
  963. ; -------------------------------
  964. ChkDoubClick                ;Check if a double click
  965.     CLR.W    DoubleClick(A5)        ;assume not
  966.     MOVE.L    WHEN(A5),D1        ;this click
  967.     SUB.L    LastClick_T(A5),D1    ;ticks elapsed since last
  968.     CMP.L    DoubleTime,D1        ;close enough togather?
  969.     BGT.S    @0            ;branch if over 'DoubleTime'
  970.     MOVE.W    WHERE(A5),D0        ;now check for position
  971.     SUB.W    LastClick_W(A5),D0    ;delta Y
  972.     BPL.S    @1            ;ABS
  973.     NEG.W    D0
  974. @1    MOVE.W    WHERE+2(A5),D1        ;delta X
  975.     SUB.W    LastClick_W+2(A5),D1
  976.     BPL.S    @2            ;ABS
  977.     NEG.W    D1
  978. @2    ADD.W    D0,D1            ;Dx+Dy
  979.     CMP.W    #3,D1            ;allow for a 3 pix max distance
  980.     BGT.S    @0
  981.     ST    DoubleClick(A5)        ;yes, it's a double click
  982. @0    MOVE.L    WHEN(A5),LastClick_T(A5)    ;Record time and…    
  983.     MOVE.L    WHERE(A5),LastClick_W(A5)    ;location
  984.     RTS
  985. ; ---------------------------------------
  986. ActMenu    BSR    paramOnStack        ;load the stack
  987.     _EnableItem            ;3 items
  988.     _EnableItem            ;to enable
  989.     _EnableItem
  990.     _DrawMenuBar
  991.     RTS
  992. DimMenu    BSR    paramOnStack        ;load the stack
  993.     _DisableItem            ;3 items
  994.     _DisableItem            ;to disable
  995.     _DisableItem
  996.     _DrawMenuBar
  997.     RTS
  998. ; ------
  999. paramonStack
  1000.     MOVE.L    (SP)+,A0            ;RTS in A0
  1001.     MOVE.L    EditHand(A5),-(SP)
  1002.     MOVE.W    #1,-(SP)            ;undo
  1003.     MOVE.L    EditHand(A5),-(SP)
  1004.     MOVE.W    #3,-(SP)            ;cut
  1005.     MOVE.L    EditHand(A5),-(SP)
  1006.     MOVE.W    #5,-(SP)            ;paste
  1007.     JMP    (A0)
  1008. ; ==========================================
  1009. MakePoly
  1010.     ShortComment    PolyBegin    ;Here starts our special Poly
  1011.     ShortComment    PicPlyClo    ;always a closed Poly in our case
  1012.     
  1013.     TST.W    Liscio(A5)        ;is our poly to be smoothed?
  1014.     BEQ.S    @1            ;branch if not
  1015.  
  1016.     MOVE.L    CommentHand(A5),A1    ;Handle to smooth verbs
  1017.     MOVE.L    (A1),A0            ;deference
  1018.     MOVEQ    #Frame+Close,D0        ;assume only closed and framed
  1019.     TST.W    CurPat(A5)        ;is our poly filled ?
  1020.     BEQ.S    @0
  1021.     ADDQ.W    #Fill,D0            ;add fill verb
  1022. @0    MOVE.B    D0,(A0)            ;set verb = Close+Frame+(Fill)
  1023.     LongComment    PolySmooth,1,A1    ;smooth flag true
  1024.  
  1025.     MOVE.L    TempRgn(A5),-(SP)        ;save clip
  1026.     _GetClip
  1027.     PEA    ZeroRect(PC)        ;if not aware of comments then no print
  1028.     _ClipRect
  1029.     BSR    DrawPoly            ;Pass laser original vertexes to be smoothed
  1030.     MOVE.L    TempRgn(A5),-(SP)
  1031.     _SetClip                ;allow others to print
  1032.     
  1033.     ShortComment    PolyIgnore    ;ignore following poly if laser
  1034.  
  1035. @1    BSR    ReDraw            ;simulate spline for non-laser printers
  1036.     ShortComment    PolyEnd        ;End special poly
  1037.     RTS
  1038. ;===========================================
  1039. InitGlobals
  1040.     CLR.W    CurPat(A5)        ;No fill pat
  1041.     MOVE.L    #$10001,CurPen(A5)    ;PenSize 1,1
  1042.     MOVE.W    #12,CurScale(A5)        ;72 dpi
  1043.     MOVE.W    #1,ChkPat(A5)        ;first pat checked
  1044.     MOVE.W    #1,Chkscale(A5)        ;72 dpi checked
  1045.     RTS
  1046. ; ----------------------------------
  1047. InitMac
  1048.     PEA    -4(A5)            ;Recite Mac pray
  1049.     _InitGraf
  1050.     _InitFonts
  1051.     _InitWindows
  1052.     _InitMenus
  1053.     CLR.L    -(SP)            ; No restart procedure
  1054.     _InitDialogs
  1055.     _TEInit
  1056.     _InitCursor
  1057.     MOVE.L    #$0000FFFF,D0        ; Flush all events
  1058.     _FlushEvents
  1059.     RTS
  1060. ; -------------------------------------
  1061. SetWindow
  1062.     MOVE.L    (A5),A0            ;Pointer to QuickDraw Globals
  1063.     LEA    screenBits(A0),A0        ;Ptr to Bounds of Screen BitMap
  1064.     MOVE.L    6(A0),WRect(A5)        ;Get & set Screen Rect
  1065.     MOVE.L    10(A0),WRect+4(A5)
  1066.     PEA    WRect(A5)
  1067.     MOVE.L    #$100010,-(SP)        ;allow 16 Pixels inside
  1068.     _InsetRect
  1069.     MOVE.L    WRect(A5),WBounds(A5)    ;Init Draging bounds Rect
  1070.     MOVE.L    WRect+4(A5),WBounds+4(A5)
  1071.  
  1072.     MOVE.L    #$400080,WSize(A5)    ;Grow Rect (64,128,768,768)        
  1073.     MOVE.L    #$3000300,WSize+4(A5)    ;(¿) should calc this rect
  1074.                     ;according to PageSetUp
  1075.     MOVE.W    MBarHeight,D0        ;Center WRect on video
  1076.     ADDI.W    #18,D0            ;Title bar
  1077.     ADD.W    D0,WRect(A5)        ;subtract Menu Height
  1078.  
  1079.     CLR.L    -(SP)            ;Create our window
  1080.     CLR.L    -(SP)
  1081.     PEA    WRect(A5)
  1082.     PEA    'Polygon'        ;document:Polygon
  1083.     MOVE.B    #-1,-(SP)
  1084.     MOVE.W    #8,-(SP)            ;has zoom box
  1085.     MOVE.L    #-1,-(SP)
  1086.     CLR.B    -(SP)
  1087.     CLR.L    -(SP)
  1088.     _NewWindow
  1089.     MOVE.L    (SP),TheWind(A5)        ;leave it on stack and save
  1090.     _SetPort
  1091.     BSR    CalcGrow
  1092.     BSR    ClipWind
  1093.     BSR    PutGrow
  1094.     RTS
  1095. ;=================================
  1096. SetMenus    
  1097.     MOVEM.L    A3/D3-D5,-(SP)        ;save stuff
  1098.     LEA    MenuHndList(A5),A3    ;Stuff with MHandles from here on
  1099.     MOVEQ    #1,D3            ;Start with Menu 1
  1100.     MOVEQ    #4-1,D4            ;4 menus (-1 for DBRA)
  1101.     MOVEQ    #0,D5            ;before ID = 0        
  1102.     BSR    PushMenus        ;sequential ordering
  1103.  
  1104.     MOVE.L    MelaHand(A5),-(SP)
  1105.     MOVE.L    #'DRVR',-(SP)
  1106.     _AddResMenu            ;yes, we support DA
  1107.                     ;add submenus
  1108.     MOVEQ    #'A',D3            ;Start with Menu 65
  1109.     MOVEQ    #2,D4            ;through menu 67
  1110.     MOVEQ    #-1,D5            ;hierarchical beforeID
  1111.     BSR    PushMenus
  1112.  
  1113.     CheckItm    PenHand,#1        ;check items
  1114.     CheckItm    FpatHand,#1
  1115.     CheckItm    PscaleHand,#1
  1116.  
  1117.     _DrawMenuBar
  1118.     MOVEM.L    (SP)+,A3/D3-D5        ;restore stuff
  1119.     RTS
  1120. ; -------------------
  1121. PushMenus
  1122.     CLR.L    -(SP)
  1123.     MOVE.W    D3,-(SP)            ;ID of Menu to get
  1124.     _GetRMenu
  1125.     MOVE.L    (SP),(A3)+        ;Save Hndl trusting global ordering
  1126.     MOVE.W    D5,-(SP)            ;Hndl was left on stack + beforeID
  1127.     _InsertMenu    
  1128.     ADDQ.W    #1,D3            ;Next ID
  1129.     DBRA    D4,PushMenus
  1130.     RTS
  1131. ; ---------------------------------------
  1132. GetHandles
  1133.     MOVE.L    #$7FFF,D0        ;ask for 32K
  1134.     _NewHandle
  1135.     BNE    Error
  1136.     MOVE.L    A0,PolyHand
  1137.     
  1138.     MOVE.L    #$FFFE,D0        ;ask for 64K
  1139.     _NewHandle
  1140.     BNE    Error
  1141.     MOVE.L    A0,PolyBuffer(A5)
  1142.     
  1143.     MOVEQ    #120,D0            ;Print Record Size
  1144.     _NewHandle
  1145.     MOVE.L    A0,PrintRec(A5)
  1146.     MOVE.L    A0,-(SP)
  1147.     prExec    PrintDefault        ;Fill it with defaults
  1148.     
  1149.     MOVEQ    #8,D0            ;enough for any comment data
  1150.     _NewHandle
  1151.     BNE    Error
  1152.     MOVE.L    A0,CommentHand(A5)
  1153.     
  1154.     CLR.L    -(SP)            ;our fill region
  1155.     _NewRgn
  1156.     MOVE.L    (SP)+,RgnHand(A5)
  1157.     
  1158.     CLR.L    -(SP)
  1159.     _NewRgn
  1160.     MOVE.L    (SP)+,TempRgn(A5)        ;A dummy region
  1161.     RTS
  1162. ;========================================
  1163. ERROR    BSR    Bippa        ;WARNING (¿)
  1164.     BSR    Bippa        ;Best Error Handler routine ever written
  1165.     BSR    Bippa        ;but I know you could do even better
  1166.     _ExitToShell
  1167. ; -----------------------------
  1168. Bippa    MOVE.W    #3,-(SP)
  1169.     _SysBeep
  1170.     RTS
  1171. ; -----------------------------
  1172. OroCurs    CLR.L    -(SP)        ;watch cursor
  1173.     MOVE.W    #4,-(SP)
  1174.     _GetCursor
  1175.     MOVE.L    (SP)+,A0
  1176.     MOVE.L    (A0),-(SP)
  1177.     _SetCursor
  1178.     RTS
  1179. ; ----------------------------------------------------
  1180. ZeroRect    DC.W    0,0,0,0
  1181. ; -----------------------------------------------------
  1182. ; ------------------- GLOBALS -------------------------
  1183. ; -----------------------------------------------------
  1184. WRect        DS.B    8    ;Window stuff
  1185. GrowBox        DS.B    8
  1186. WBounds        DS.B    8
  1187. WSize        DS.B    8
  1188. TheWind        DS.L    1
  1189. WINDOW        DS.L    1
  1190.  
  1191. MenuHndList    DS.L    0    ;do not change this ordering!
  1192. MelaHand        DS.L    1    ;Menu Handles
  1193. FileHand        DS.L    1
  1194. EditHand        DS.L    1
  1195. DoHand        DS.L    1
  1196. PenHand        DS.L    1    ;Hierarchical Menu Handles
  1197. FpatHand        DS.L    1
  1198. PscaleHand    DS.L    1
  1199.  
  1200. EVENTRECORD    DS.B    0    ;My event.
  1201. WHAT        DS.W    1
  1202. MESSAGE        DS.L    1
  1203. WHEN        DS.L    1
  1204. WHERE        DS.L    1
  1205. MODIFY        DS.W    1
  1206.  
  1207. MENU        DS.L    1    ;Other…
  1208. PolyBuffer    DS.L    1
  1209. PolyDrawn    DS.W    1    
  1210. whileDrawing    DS.W    1
  1211. NumPoints    DS.W    1
  1212. BytesWritten    DS.W    1
  1213. LastPoint    DS.L    1
  1214. CurPoint        DS.L    1
  1215. OldPoint        DS.L    1
  1216. MousLoc        DS.L    1
  1217. LastClick_T    DS.L    1
  1218. LastClick_W    DS.L    1
  1219. DoubleClick    DS.W    1
  1220. CurPat        DS.W    1
  1221. CurPen        DS.L    1
  1222. CurScale        DS.W    1
  1223. ChkPat        DS.W    1
  1224. Chkscale        DS.W    1
  1225. Liscio        DS.W    1
  1226. RgnHand        DS.L    1
  1227. TempRgn        DS.L    1
  1228. CommentHand    DS.L    1
  1229. DskName        DS.B    64
  1230. SavePort        DS.L    1
  1231. PrintPort    DS.L    1
  1232. PrintRec        DS.L    1
  1233. PrStatus        DS.B    26
  1234. ItmHit        DS.W    1